﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;

namespace WastedMechanics
{
    public class GuiFrame
    {
        public string Name;
        public Overlay Overlay;
        public bool IsZOrderFixed;        

        public GuiControl Control;
        
        public GuiFrame(string name, ushort zorder)
        {
            Name = name;            
            Overlay = OverlayManager.Singleton.Create(Name);
            
            Overlay.Show();
            Overlay.ZOrder = zorder;
        }

        public void SetControl(GuiControl control)
        {
            if (Control != null)            
                Overlay.Remove2D(Control.Panel);                           

            Control = control;

            if (control != null)                           
                Overlay.Add2D(control.Panel);            
        }

        public void Destroy()
        {
            if (Control != null)
                Overlay.Remove2D(Control.Panel);
            Control = null;
            OverlayManager.Singleton.Destroy(Overlay);
        }

        public void Update()
        {
            if (Control != null)
                Control.Update();                          
        }

        public void GiveInput()
        {
            if (Control != null)
                Control.GiveInput();            
        }

        public bool ContainsPoint(Vector2 pt)
        {            
            return (Control != null && Control.ContainsPoint(pt));
        }

        public ushort ZOrder
        {
            get
            {
                return Overlay.ZOrder;
            }
            set
            {
                Overlay.ZOrder = value;
            }
        }        
    }
}
